const workCenter = {
  state: {
    // 列表数据
    listData: {},
    // 详情数据
    detailData: {
      factoryId: '',
      workshopId: '',
      workgroupId: '',
      deviceIds: '',
      staffIds: '',
      workstageIds: '',
      deviceIdsList: [],
      staffIdsList: [],
      workstageIdsList: [],
      deviceNames: '',
      staffNames: '',
      workstageNames: ''
    },
    // 树形数据
    treeList: [],
    // 工序映射工作中心
    workstageMapping: []
  },
  mutations: {
    setSecondValue: (state, value) => {
      if (state.detailData.workshopId) {
        state.detailData.workshopId = value
      }
      if (state.detailData.workgroupId) {
        state.detailData.workgroupId = value
      }
    },
    setThirdValue: (state, value) => {
      if (state.detailData.workgroupId) {
        state.detailData.workgroupId = value
      }
    },
    setValue: (state, value) => {
      if (Array.isArray(value)) {
        value.forEach((item) => {
          state.detailData[item.key] = item.value
        })
      }
    },
    clearDetail: (state, value) => {
      if (!value) return false
      for (let key in state.detailData) {
        if (Array.isArray(state.detailData[key])) {
          state.detailData[key] = []
        } else {
          state.detailData[key] = ''
        }
      }
    }
  },
  actions: {
    setSecondValue: ({dispatch, commit}, value) => {
      commit('setSecondValue', value)
    },
    setThirdValue: ({dispatch, commit}, value) => {
      commit('setThirdValue', value)
    },
    setValue: ({dispatch, commit}, value) => {
      commit('setValue', value)
    },
    clearDetail: ({dispatch, commit}, value) => {
      commit('clearDetail', value)
    }
  }
}

export default workCenter
